package eg.com.itiga.repository.user;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import eg.com.itiga.domain.User;
import eg.com.itiga.repository.exception.DataException;
import eg.com.itiga.repositoryimpl.base.BaseDaoImpl;
import eg.com.itiga.repositoryimpl.base.HibernateUtil;

public class UserDaoImpl extends BaseDaoImpl implements UserDao{

	
	public User getUserByCredential(User user) throws DataException {
		// TODO Auto-generated method stub
		Session session = HibernateUtil.getCurrentSession();
		User resultedUser = new User();
		try {
			//session.
			Criterion usernameEq = Restrictions.eq("userName", user.getUserName());
			Criterion userpasswordEq = Restrictions.eq("userPassword", user.getUserPassword());
			
			Criteria criteria = session.createCriteria(User.class);
			criteria.add(usernameEq);
			criteria.add(userpasswordEq);
				
			resultedUser = (User) criteria.uniqueResult();

		} catch (HibernateException e) {
			throw new DataException("Data Exception");
		}
		return resultedUser;
	}

}
